package com.cskaoyan.market.controller.admin;

import com.cskaoyan.market.db.domain.MarketRegion;
import com.cskaoyan.market.db.domain.SelfMarketRegion;
import com.cskaoyan.market.service.MarketRegionService;
import com.cskaoyan.market.service.impl.MarketRegionServiceImpl;
import com.cskaoyan.market.util.JacksonUtil;
import com.cskaoyan.market.util.ResponseUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@RestController
@RequestMapping("admin/region")
public class RegionController {
    @Autowired
    MarketRegionService marketRegionService;

    @GetMapping("list")
    private void list(HttpServletRequest req, HttpServletResponse resp) throws IOException {

        List<MarketRegion> regionList = marketRegionService.getRegionList(0);
        List<SelfMarketRegion> selfMarketRegions = marketRegionService.packageMarketRegionList(regionList);
        Object ok = ResponseUtil.okList(selfMarketRegions);
        ObjectMapper objectMapper = JacksonUtil.getObjectMapper();
        String s = objectMapper.writeValueAsString(ok);
        resp.getWriter().println(s);
    }

}
